//
// * Copyright (c) 2002-2010 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.kernel
{


	using AdaptiveCacheManager = org.neo4j.kernel.impl.cache.AdaptiveCacheManager;
	using LockReleaser = org.neo4j.kernel.impl.core.LockReleaser;
	using NeoModule = org.neo4j.kernel.impl.core.NeoModule;
	using EventModule = org.neo4j.kernel.impl.event.EventModule;
	using IdGeneratorModule = org.neo4j.kernel.impl.persistence.IdGeneratorModule;
	using PersistenceModule = org.neo4j.kernel.impl.persistence.PersistenceModule;
	using LockManager = org.neo4j.kernel.impl.transaction.LockManager;
	using TxModule = org.neo4j.kernel.impl.transaction.TxModule;

///
/// <summary> * A non-standard configuration object. </summary>
/// 
	public class Config
	{
		private EventModule eventModule;
		private AdaptiveCacheManager cacheManager;
		private TxModule txModule;
		private LockManager lockManager;
		private LockReleaser lockReleaser;
		private PersistenceModule persistenceModule;
		private bool create = false;
		private string persistenceSourceName;
		private IdGeneratorModule idGeneratorModule;
		private NeoModule neoModule;
		private string storeDir;
		private readonly Map<object, object> @params;

		private readonly bool readOnly;

		internal Config(string storeDir, Map<object, object> @params)
		{
			this.storeDir = storeDir;
			this.params = @params;
			string readOnlyStr = (string) @params.get("read_only");
			if (readOnlyStr != null && readOnlyStr.ToLower().Equals("true"))
			{
				readOnly = true;
			}
			else
			{
				readOnly = false;
			}
			@params.put("read_only", readOnly);
			eventModule = new EventModule();
			cacheManager = new AdaptiveCacheManager();
			if (!readOnly)
			{
				txModule = new TxModule(this.storeDir);
			}
			else
			{
				txModule = new TxModule(true);
			}
			lockManager = new LockManager(txModule.getTxManager());
			lockReleaser = new LockReleaser(lockManager, txModule.getTxManager());
			persistenceModule = new PersistenceModule();
			idGeneratorModule = new IdGeneratorModule();
			neoModule = new NeoModule(cacheManager, lockManager, txModule.getTxManager(), idGeneratorModule.getIdGenerator(), readOnly);
		}

		internal virtual void setNeoPersistenceSource(string name, bool create)
		{
			persistenceSourceName = name;
			this.create = create;
		}

		internal virtual string getPersistenceSource()
		{
			return persistenceSourceName;
		}

		internal virtual bool getCreatePersistenceSource()
		{
			return create;
		}

		public virtual EventModule getEventModule()
		{
			return eventModule;
		}

		public virtual TxModule getTxModule()
		{
			return txModule;
		}

		public virtual NeoModule getNeoModule()
		{
			return neoModule;
		}

		public virtual PersistenceModule getPersistenceModule()
		{
			return persistenceModule;
		}

		internal virtual IdGeneratorModule getIdGeneratorModule()
		{
			return idGeneratorModule;
		}

		public virtual LockManager getLockManager()
		{
			return lockManager;
		}

		public virtual LockReleaser getLockReleaser()
		{
			return lockReleaser;
		}

		public virtual Map<object, object> getParams()
		{
			return this.params;
		}

		internal virtual bool isReadOnly()
		{
			return readOnly;
		}
	}

}